package cn.xieyang.gen.handler;

import cn.xieyang.gen.config.DBConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConfigHandler {

    public static Connection getConn(DBConfig dbConfig) throws SQLException, ClassNotFoundException {
        // 1. 加载MySQL JDBC驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        // 2. 建立数据库连接
        Connection conn = DriverManager.getConnection(dbConfig.getUrl(), dbConfig.getUserName(), dbConfig.getPassword());
        return conn;
    }

}
